﻿using System;
using System.Windows.Input;
using LEShortcut.Helper;
using LEShortcut.Models.Views.Pages;
using Microsoft.Win32;

namespace LEShortcut.Commands
{
    public class BrowseShortcutCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (parameter != null)
            {
                var context = parameter as HomeViewContext;
                var openDialog = new OpenFileDialog
                {
                    Title = "ChooseShortcutTitle".GetI18NString(),
                    DereferenceLinks = false,
                    Filter = "ChooseShortcutExcutableFilter".GetI18NString(),
                    Multiselect = true
                };
                bool? showDialog = openDialog.ShowDialog();
                if (showDialog != null && (bool) showDialog)
                {
                    string[] paths = PathHelper.ValidatedExtractor(openDialog.FileNames);
                    CommandHelper.ParserShortcuts(paths, context);
                }
            }
        }


        public event EventHandler CanExecuteChanged;
    }
}